<template>
    <div>
        <div v-for="good in goods" :key="good.id">
            <span style="margin-right:30px">{{good.name}}----{{good.price}}</span>
            <button @click="addToCart(good)">加入购物车</button>
        </div>
    </div>
</template>
<script>
export default {
    data () {
        return {
            goods: [
                { id:1, name:"good1", price: 10},
                { id:2, name:"good2", price: 15},
                { id:3, name:"good3", price: 20},
                { id:4, name:"good4", price: 25},
            ]
        }
    },
    methods: {
        addToCart(val) {
            this.$emit('addCart', val)
        }
    }
}
</script>